// $(function () {
//     $.ajax({
//         url: 'http://localhost:8080/back/front/type',
//         dataType: 'json',
//         success: function (data) {
//             console.log("类别有："+data)
//             setType(data.data)
//         }
//
//     })
//
// })



function setType(data) {
    let  html=''
    for (let i = 0; i <data.lenght ; i++) {
        html+=' <div> <div onclick="type(this)">+data.name+</div></div>'

    }
    $("#typee").html(html)

}

//判断点击的哪个种类
    function type(obj) {


        //获取到点击的种类值
        let val = $(obj).html();


        $("#type div > div").css({"font-weight":"","border-bottom": ""});
        $(obj).css({"font-weight":"bold","border-bottom": "3px solid green"});

        layui.use(['laypage', 'layer'], function(){
            var laypage = layui.laypage
                ,layer = layui.layer;

            //总页数大于页码总数
            laypage.render({
                elem: 'demo1'
                ,count: getProductTypeSum(val) //数据总数
                ,limit:8 //页码
                ,jump: function(obj){
                    let pageDatas ={"count":obj.count,"curr":obj.curr,"pages":obj.pages,"limit":obj.limit};
                    // console.log("分页参数",obj)
                    $.ajax({
                        url:"http://localhost:8080/back/front/findByCategory",
                        dataType:'json',
                        data: {"page":pageDatas.curr,"limit":pageDatas.limit,"typeName":val},
                        success: function (res) {
                            let val = '';
                            // console.log("前端终类产品返回的数据",res)
                            for (let i = 0; i < res.data.length; i++) {

                                val +='<div>\n' +
                                    '                                <div>\n' +
                                '                                    <img src="'+res.data[i].imgHref+'" alt="" onclick="detail('+res.data[i].id+')">\n' +

                                    '                                </div>\n' +
                                    '                                <div>\n' +
                                    '                                    <div>'+res.data[i].name+'</div>\n' +
                                    '                                    <div>'+res.data[i].forWho+'</div>\n' +
                                    '                                    <div>\n' +
                                    '                                        <div>价格</div>\n' +
                                    '                                        <div>'+res.data[i].normalPrice+'</div>\n' +
                                    '                                    </div>\n' +
                                    '                                </div>\n' +
                                    '                            </div>'
                            }
                            $("#bookContent").html(val)

                        },
                    })
                }
            })
        })









    }

    function getProductTypeSum(typeName) {
    let count;

    $.ajax({
        url:'http://localhost:8080/back/front/productTypeSum',
        dataType:'json',
        data:{"typeName":typeName},
        async:false,//关闭异步
        success:function (data) {
            count = data.data

        }
    })
    return count;
}

